Dynomotion

Group: DynoMotion Message: 9565 From: eric_kato_sanders Date: 5/28/2014
Subject: Small tool table glitch
Hi Tom,
I was getting a tool table error with the latest version. The problem was that one of my comments contained a quote character which broke the parsing.  I rewrote the parsing to isolate the image name first, and then the comment.  This will now allow a quote in the comment.
I modified the int CEditToolFile::LoadFile(CString File) to this:

int CEditToolFile::LoadFile(CString File)
{
    int result,i,Revision=0;
    CString Comment,Image,s;
    int ID,Slot;
    double Diameter,Length,Xoffset,Yoffset;
   CStdioFile f;
   if(!f.Open(File, CFile::modeRead|CFile::typeText))
   {
      AfxMessageBox("Unable to open Tool Table file:\r\r" + File);
      return 1;
   }

   if(!f.ReadString(s))
   {
      AfxMessageBox("Invalid Tool Table file (line 1):\r\r" + File);
      f.Close();
      return 1;
   }
    s.MakeUpper();

    if (s.Find("COMMENT")==-1 || s.Find("DIAM")==-1 || s.Find("LEN")==-1)
    {
        AfxMessageBox("Invalid Tool Table file (line 1):\r\r" + File);
        f.Close();
        return 1;
    }

    if (s.Find("XOFFSET")>0 && s.Find("YOFFSET")>0 && s.Find("IMAGE")>0) Revision = 1;


    int n,Tool=0,line=1;

    while (f.ReadString(s))
    {
      // remove whitespace
         s.Trim();
            line++;

            if (!s.IsEmpty())
            {
                if (Tool >= MAX_TOOLS)
                {
                    AfxMessageBox("Invalid Tool Table file:\r\r" + File + "\r\rToo many Tools Max Allowed is 99");
                    f.Close();
                    return 1;
                }

                if (Revision==0)
                {
                    result = sscanf(s,"%d%d%lf%lf%n",&Slot,&ID,&Length,&Diameter,&n);
                    Xoffset=Yoffset=0;

                    if (result !=4)
                    {
                        CString err;
                        err.Format("Line %d doesn't have 4 valid numbers",line);
                        AfxMessageBox("Invalid Tool Table file:\r\r" + File + "\r\r" + err);
                        f.Close();
                        return 1;
                    }
                }
                else
                {
                    result = sscanf(s,"%d%d%lf%lf%lf%lf%n",&Slot,&ID,&Length,&Diameter,&Xoffset,&Yoffset,&n);
                    if (result !=6)
                    {
                        CString err;
                        err.Format("Line %d doesn't have 6 valid numbers",line);
                        AfxMessageBox("Invalid Tool Table file:\r\r" + File + "\r\r" + err);
                        f.Close();
                        return 1;
                    }
                }

                s.Delete(0,n);

            Comment = s;
                //remove beginning and ending whitespace
            Comment.Trim();
                if (Revision==0)
                {
                    Image = "";
                    PutTool(Tool,Slot,ID,Length,Diameter,Xoffset,Yoffset,Comment,Image);
                    Tool++;
                }
                else
                {
               BOOL bImageSuccess = TRUE;
               BOOL bCommentSuccess = TRUE;
               //first isolate our image name
               if(Comment.Right(1) == '"')
               {
                  Comment.Delete(Comment.GetLength()-1,1);
                  i=Comment.ReverseFind('"');
                  if (i!=-1)
                  {
                     Image = Comment.Mid(i+1);
                     Comment = Comment.Left(i-1);
                     Comment.Trim();
                  }
                  else
                  {
                     bImageSuccess = FALSE;
                  }
               }

               if(bImageSuccess)
               {
                  //Isolate our comment
                  if(Comment.GetAt(0) == '"' && Comment.Right(1) == '"')
                   {
                      Comment.Delete(0,1);
                      Comment.Delete(Comment.GetLength()-1,1);
                   }
                   else
                   {
                      bCommentSuccess = FALSE;
                   }
               }
               if(!bImageSuccess)
               {
                  CString err;
                  err.Format("Line %d doesn't have matching quotation marks for Image",line);
                  AfxMessageBox("Invalid Tool Table file:\r\r" + File + "\r\r" + err);
                  f.Close();
                  return 1;
               }

                if (!bCommentSuccess)
                    {
                        CString err;
                        err.Format("Line %d doesn't have quotation marks for comment",line);
                        AfxMessageBox("Invalid Tool Table file:\r\r" + File + "\r\r" + err);
                  f.Close();
                        return 1;
                    }

                    PutTool(Tool,Slot,ID,Length,Diameter,Xoffset,Yoffset,Comment,Image);
                    Tool++;
                }
            }
       
    }
   f.Close();

    // Blank out others
    for (int i=Tool; i<MAX_TOOLS; i++)
    {
        PutTool(i,0,0,0,0,0,0,"","");
    }

    m_nTools=Tool;  // remember how many tools defined
    return 0;
}

Eric

Group: DynoMotion Message: 9571 From: Tom Kerekes Date: 5/28/2014
Subject: Re: Small tool table glitch
Thanks Eric.

This change will be in the next Release.

Regards
TK